package com.itheima.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.itheima.dao.ReportMapper;
import com.itheima.po.*;
import com.itheima.pojo.Result;
import com.itheima.service.ReportService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Resource
    ReportMapper reportMapper;
    /**
     * 统计性别数据
     * @return
     */
    @Override
    public Result empGenderData() {
        List<SexCount> sexCount = reportMapper.empGenderData();
        return Result.success(sexCount);
    }

    @Override
    public Result empJobData() {
        List<JobPeople> job = reportMapper.empJobCount();
        List<String> jobList = new ArrayList<>();
        List<String> data = new ArrayList<>();
        job.forEach(t->{
            jobList.add(t.getJobName());
            data.add(t.getCount());
        });
//        JobCount jobCount =new JobCount();
//        jobCount.setJobList(jobList);
//        jobCount.setDataList(data);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("jobList",jobList);
        jsonObject.put("dataList",data);
        return Result.success(jsonObject);

    }

    @Override
    public Result degreeData() {
        List<CountVO> count = reportMapper.degreeData();
        return Result.success(count);
    }

    @Override
    public Result studentCount() {
        List<CountVO> count = reportMapper.studentCount();
        StudentCount stuCount = new StudentCount();
        List<String> name =new ArrayList<>();
        List<Integer> value =new ArrayList<>();
        count.forEach(t ->{
            name.add(t.getName());
            value.add(t.getValue());
        });
//        stuCount.setClazzList(name);
//        stuCount.setDataList(value);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("clazzList",name);
        jsonObject.put("dataList",value);
        return Result.success(jsonObject);

    }

}
